﻿@page "/Admin/Menus"
@attribute [TabItemOption(Text = "菜单管理", Icon = "fa-solid fa-bars")]
@using BlazorAdmin.Models
@using BlazorAdmin.Web.Shared.Components
@using BlazorAdmin.Web.Shared.Models

<AdminTable TItem="Navigation" ExtendButtonColumnWidth=200 CustomerSearchModel=SearchModel
            IsTree=true ShowCardView=false
            OnTreeExpand="OnTreeExpand" TreeNodeConverter="TreeNodeConverter" ModelEqualityComparer="ModelEqualityComparer"
            OnQueryAsync="OnQueryAsync">
    <TableToolbarTemplate>
        <TableToolbarButton TItem="Navigation" Color="Color.Info" Icon="fa-solid fa-users-gear" Text="分配角色"
                            IsEnableWhenSelectedOneRow="true" IsShow="@AuthorizeButton("assignRole")"
                            OnClickCallback="menus => OnAssignmentRoles(menus.First())" />
    </TableToolbarTemplate>
    <TableColumns>
        <TableColumn @bind-Field="@context.Name" Filterable="true" Searchable="true" Width="200"></TableColumn>
        <TableColumn @bind-Field="@context.SortNo" Width="50"></TableColumn>
        <TableColumn @bind-Field="@context.Icon" Width="50" Align="Alignment.Center">
            <Template Context="v">
                <i class="text-info cell-icon @v.Value"></i>
            </Template>
        </TableColumn>
        <TableColumn @bind-Field="@context.Url"></TableColumn>
        <TableColumn @bind-Field="@context.Category" Filterable="true"></TableColumn>
        <TableColumn @bind-Field="@context.Target" Filterable="true" Lookup="Targets"></TableColumn>
        <TableColumn @bind-Field="@context.IsResource" Filterable="true"></TableColumn>
        <TableColumn @bind-Field="@context.Application" Filterable="true" Lookup="Apps"></TableColumn>
    </TableColumns>
    <EditTemplate Context="v">
        <MenuEditor Value="v" ParementMenus="ParementMenus" Targets="Targets" Apps="Apps" />
    </EditTemplate>
    <RowButtonTemplate>
        <TableCellButton Size="Size.ExtraSmall" IsShow="@AuthorizeButton("assignRole")" Color="Color.Info" Icon="fa-solid fa-users-gear" Text="分配角色" OnClick="() => OnAssignmentRoles(context)" />
    </RowButtonTemplate>
    <CustomerSearchTemplate>
        @if (context is MenusSearchModel searchModel)
                {
        <MenusSearch @bind-Value="searchModel"></MenusSearch>
                }
    </CustomerSearchTemplate>
</AdminTable>
